
<?php
$property = get_property_by_link($param[1]);
//Update View Count
$db->exec_update("property",array("view_count"=>$property["view_count"]+1),'`id`='.intval($property["id"]));
//Get Property Images
$rs_img = get_property_images($property["id"]);
$arr_contact=get_property_contact($property["id"]);
$have_img = false;	
$class_des = 2;	  
if($db->num_rows($rs_img) > 0) {
    $have_img = true;
    $class_des = "";
}
// GET Geo
$geo = get_arr_city($property["geo_id"]);
//=================================
// GET Member Info
$member_info = get_member_info($property["user_id"]);
?>


<script language="javascript" type="text/javascript">

    function closeGeo(id){
        $("#"+id).slideUp();
    }
    function show_tab(mode)
    {
        $('#div_tab1').hide();
        $('#div_tab2').hide();


        var tab1  = document.getElementById('tab1');
        var tab2 = document.getElementById('tab2');


        tab1.className = '';
        tab2.className = '';


        switch(mode)
        {
            case 1 : tab1.className = 'current'; $('#div_tab1').show(); break;
            case 2 : tab2.className = 'current'; $('#div_tab2').show(); break;
        }
    }
    function get_property_ajax(tab,page,mode,price,current_id){

        $.ajax({
            url: AJAX_PROCESS_URL+'get_property_'+mode+'/'+tab+'/'+page+'/'+price+'/'+current_id,
            type: 'GET',
            data: "",
            error: function(){
                //alert('error!');
            },
            success: function(data){

                $("#div_tab"+tab).html(data);

            }
        });

    }
</script>

<div class="right_content_SBDS" >
    <div class="toplink"><img src="<?php echo SITE_IMAGES_URL; ?>/iconhome.gif" /><a href="#"><b>[Trang chủ]</b></a>&raquo;<a href="#">[Sản phẩm giao dịch]</a>&raquo;<a href="#" class="pagehere">[BĐS Bán]</a></div>
    <div class="top_san_BDS">
        <div class="top_san_BDS_l">

            [Bạn đang xem tin tại]: <font class="textbold">[Việt Nam]</font> &raquo;  <span id="propertyCityLink"><font class="textbold"><?php echo $geo["city"];?></font><img src="/images/arrow6.gif" /></span> <font class="textbold"><?php echo $geo["district"];?></font>
            <div id="ShowAllCities" style="display:none;">
                <div class="close"><a href="javascript: closeGeo('ShowAllCities');"><img src="/images/close.gif" /></a></div>
                <div class="content_form">
                    <div class="item1">
                        <?php
                        $allCity = getAllCityByParent('1');
                        $i=0;
                        while($row = $db->fetch_array($allCity)){
                            $i++;
                            if($i==1 || $i==2){
                                echo '<a href="'.get_link("property","geo",$row['geo_link']).'"><b>'.$row['geo_title'].'</b></a><br />';
                            }else{
                                echo '<a href="'.get_link("property","geo",$row['geo_link']).'">'.$row['geo_title'].'</a><br />';
                            }
                        }
                        ?>
                    </div>

                    <div class="item1">
                        <?php
                        $allCity = getAllCityByParent('2');
                        $i=0;
                        while($row = $db->fetch_array($allCity)){
                            $i++;
                            if($i==1 || $i==2){
                                echo '<a href="'.get_link("property","geo",$row['geo_link']).'"><b>'.$row['geo_title'].'</b></a><br />';
                            }else{
                                echo '<a href="'.get_link("property","geo",$row['geo_link']).'">'.$row['geo_title'].'</a><br />';
                            }
                        }
                        ?>
                    </div>

                    <div class="item1">
                        <?php
                        $allCity = getAllCityByParent('3');
                        $i=0;
                        while($row = $db->fetch_array($allCity)){
                            $i++;
                            if($i==1 || $i==2){
                                echo '<a href="'.get_link("property","geo",$row['geo_link']).'"><b>'.$row['geo_title'].'</b></a><br />';
                            }else{
                                echo '<a href="'.get_link("property","geo",$row['geo_link']).'">'.$row['geo_title'].'</a><br />';
                            }
                        }
                        ?>
                    </div>

                </div>
            </div>
            <p>[Có] <font class="textbold">4463</font> [tài sản trong mục] <font class="textbold"><?php echo $property["cat_title"];?></font></p>

        </div>


    </div>
    <div class="Right_san_ct">
        <div class="extrafunction">
            <ul >
                <li>
                    <img src="/images/luu.gif" /><a href="#">[Lưu tin]</a
                </li>
                <li>
                    <img src="/images/email.gif" /><a class="thickbox" title="Gửi cho bạn bè" href="#TB_inline?height=450&width=600&inlineId=sendFriend">[Gửi bạn bè]</a>
                </li>
                <li>
                    <img src="/images/print.gif" /><a href="JavaScript:window.print()">[In ra]</a>
                </li>
                <li class="goback"><img src="<?php echo SITE_IMAGES_URL; ?>/quaylai.gif" /><a href="javascript:history.back();">[Quay lại]</a></li>
            </ul>
        </div>


        <div class="<?php if($property["type"]=='rent') echo 'title4'; else echo 'title3';?>"><div class="title_test"><?php echo $property["title"];?></div></div>
        <div class="pricediv">
            <ul >
                <li>
                    <ul style="margin-top: -10px;margin-left: -10px">
                        <li style="float: none;padding: 5px;">[Trạng thái]: <font color="#f58220" style="font-weight:bold"><?php
                                switch($property["status"])
                                {
                                    case 'actived':
                                        echo '[Đang giao dịch]';
                                        break;
                                    case 'pending':
                                        echo '[Chờ kích hoạt]';
                                        break;
                                    case 'closed':
                                        echo '[Đã giao dịch (closed)]';
                                        break;
                                }
                                ?>
                        </font></li>
                        <li style="float: none;padding: 5px;">[Ngày đăng]: <?php echo get_my_date($property["create_date"],'d/m/Y');?></li>
                        <li style="float: none;padding: 5px;">[Lượt xem]: <?php echo $property["view_count"];?></li>
                    </ul>

                </li>
                <li style="float:right">
                    <table cellpadding="5" cellspacing="0" width="400px" rules="none">

                        <tr >
                            <td width="40%" style="background-color: #c8dff3;color:#000; font-weight: bold;">[Tổng giá]</td>
                            <td width="40%" style="background-color: #c8dff3;color:#000; font-weight: bold;">[Theo m2]</td>
                            <td  class="money"><div><a id="txtPriceVND<?php echo $i;?>" href="javascript: void(0);" onclick="priceExchange(<?php echo $i;?>,'vnd');">VNĐ</a><img src="<?php echo SITE_IMAGES_URL; ?>/icon_check.gif" id="imgVND<?php echo $i;?>"></div></td>
                        </tr>
                        <tr>
                            <td  ><div id="showPriceTotalVND<?php echo $i;?>"><?php $totalPrice = $property['price']*$property['area_build']; if($totalPrice){echo get_price_string($totalPrice);}else{echo 'N/A';}?><input type="hidden" id="priceTotal<?php echo $i;?>" value="<?php echo $totalPrice;?>"/></div><div id="showPriceTotalUSD<?php echo $i;?>"></div></td>
                            <td  ><div id="showPriceM2VND<?php echo $i;?>"><input type="hidden" id="priceM2<?php echo $i;?>" value="<?php echo $property['price'];?>"/><?php echo get_price_string($property['price']);?></div><div id="showPriceM2USD<?php echo $i;?>"></div></td>
                            <td  class="money">
                                <div><a id="txtPriceUSD<?php echo $i;?>" href="javascript: void(0);" onclick="priceExchange(<?php echo $i;?>,'usd');">USD</a><img src="<?php echo SITE_IMAGES_URL; ?>/icon_check.gif" style="display: none" id="imgUSD<?php echo $i;?>"></div>
                            </td>
                        </tr>

                    </table>
                </li>
            </ul>
        </div>

        <script language="javascript" type="text/javascript">
            var usdForexs = vCosts[0];
            //var usdForexs = 19.070;
            function format_number(dec,fix) {
                fixValue = parseFloat(Math.pow(10,fix));
                retValue = parseInt(Math.round(dec * fixValue)) / fixValue;
                return retValue;
            }
            function priceExchange(htmlIdIndex,type){
                if(type=='usd'){
                    var totalUSD = ($('#priceTotal'+htmlIdIndex).val()*1000)/usdForexs;
                    var priceM2 = ($('#priceM2'+htmlIdIndex).val()*1000)/usdForexs;
                    $('#showPriceTotalVND'+htmlIdIndex).hide();
                    if(totalUSD!=0){
                        $('#showPriceTotalUSD'+htmlIdIndex).html(format_number(totalUSD,3));
                    }else{
                        $('#showPriceTotalUSD'+htmlIdIndex).html('N/A');
                    }
                    $('#showPriceTotalUSD'+htmlIdIndex).show();

                    $('#showPriceM2VND'+htmlIdIndex).hide();
                    $('#showPriceM2USD'+htmlIdIndex).html(format_number(priceM2,3));
                    $('#showPriceM2USD'+htmlIdIndex).show();
                    $('#imgVND'+htmlIdIndex).attr('display','none','style');
                    $('#imgUSD'+htmlIdIndex).attr('display','inline','style');

                }else if(type=='vnd'){
                    $('#showPriceM2USD'+htmlIdIndex).hide();
                    $('#showPriceM2VND'+htmlIdIndex).show();
                    $('#showPriceTotalUSD'+htmlIdIndex).hide();
                    $('#showPriceTotalVND'+htmlIdIndex).show();
                    $('#imgVND'+htmlIdIndex).attr('display','inline','style');
                    $('#imgUSD'+htmlIdIndex).attr('display','none','style');
                }
            }
        </script>

        <div class="topright1">
            <ul>

                <li>[Ngày đăng]: <?php echo get_my_date($property["create_date"],'d/m/Y');?></li>
                <li>[Lượt xem]: <?php echo $property["view_count"];?></li>

            </ul>
        </div>

        <div style="float:left;height:300px; margin:10px; border:1px #b1c4d5 solid;width: 710px;position:relative;" id="mapcontainer"></div>
        <script language="javascript" type="text/javascript">
            $(function(){
                $("#mapcontainer").gMap({
                    controls: true,
                    scrollwheel: false,
                    icon: { image: "<?php echo SITE_IMAGES_URL; ?>/gmap_pin.png",iconsize: [20, 30],iconanchor: [12, 30],infowindowanchor: [12, 0] },
                    zoom: 14,
                    markers: [{
<?php if($property["map"]=='')echo "latitude: 21.028711, longitude: 105.852456";else echo $property["map"]; ?>,
                    html: "<div class=\"MiniPopup\"><span class=\"psptitle\"><?php echo limitWord(htmlentities_utf8($property["title"]),7);?></span><br><img src=\"<?php echo SITE_IMAGES_URL; ?>/start_yellow.gif\"><img src=\"<?php echo SITE_IMAGES_URL; ?>/start_yellow.gif\"><img src=\"<?php echo SITE_IMAGES_URL; ?>/start_yellow.gif\"><img src=\"<?php echo SITE_IMAGES_URL; ?>/start_yellow.gif\"><img src=\"<?php echo SITE_IMAGES_URL; ?>/start_yellow.gif\"><p class=\"Content\"><div class=\"imagemap\"\><img alt=\"picture\" id=\"pi\" class=\"Image\" src=\"<?php if(get_property_thumb($property['thumb'])==null) echo SITE_IMAGES_URL."/noImage.gif"; else echo get_property_thumb($property['thumb']);?>\"></div><br><b>[Tổng giá]:</b>&nbsp;&nbsp;<?php echo get_price_string($property["price"]*$property["area_build"]);?><p><b>[Diện tích]:</b>&nbsp;&nbsp;<?php echo format_thousand($property["area_build"])." m2";?><p><b>[Hướng]:</b>&nbsp;&nbsp;\t<?php echo showData(show_direction($property["direction"]));?></div>",popup: true}]
        });});



        </script>
        <div class="line_info2_slide" style="width:705px">

            <?php if($have_img) {
                ?>

            <div id="demo" style="overflow:hidden;position:relative; width: 100%; height: auto">
                <table border="0" align="left" cellpadding=0 bgcolor="#ffffff" cellspace="0">
                    <tr>
                        <td id="demo1" valign="top" width="1335">
                            <table border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr valign="top" bgcolor="#FFFFFF">
                                    <?php
                                    $i=0;
                                    while($rs=$db->fetch_array($rs_img)) {
                                        $i++;
                                        ?>
                                    <td align=middle>
                                        <table cellspacing=0 cellpadding=0 border=0 >
                                            <tr>
                                                <td align="center" style="padding: 0px 5px 0px 5px;">
                                                    <div id="gallery">
                                                        <a  href="<?php echo get_property_thumb($rs['image'],'257-256'); ?>">
                                                            <span></span>
                                                            <img class="thum_tv" style="width:120px;height: 90px"  src="<?php echo get_property_thumb($rs['image'],'91-71');?>" <?php echo 'id="img_'.$i;?> name="" alt="" title="" />
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                    <?php
                                }
                                ?>
                                </tr>
                            </table>
                        </td>
                        <td id="demo2" valign="top" width="19">&nbsp;</td>
                    </tr>
                </table>

            </div>
            <?php if($db->num_rows($rs_img)>=5)
            {
                ?>
            <script type="text/javascript" language="javascript">

                var td_demo = document.getElementById("demo");
                var td_demo1 = document.getElementById("demo1");
                var td_demo2 = document.getElementById("demo2");
                td_demo2.innerHTML = td_demo1.innerHTML;
                var demo_left = 0;
                var demo_width = td_demo1.offsetWidth;
                function Marquee()
                {
                    demo_left++;
                    if (demo_left>=demo_width)
                    {
                        demo_left-=demo_width;
                    }
                    td_demo.scrollLeft = demo_left;
                    //setTimeout("Marquee()", speed);
                }
                var speed = 50;
                var MyMar = setInterval ("Marquee()", speed);
                td_demo.onmouseover = function()
                {
                    clearInterval (MyMar) ;
                }
                td_demo.onmouseout = function()
                {
                    MyMar = setInterval ("Marquee()", speed);
                }
            </script>
            <?php
        }
    }
    ?>

        </div>



        <div class="info_content">
            <hr style="width:95%;border-top:1px solid #f87310;size:0.5">
            <div class="line_info" style="padding-right:10px">
                <ul>
                    <li><strong>[Loại địa ốc]:</strong></li>
                    <li><?php echo showData($property["cat_title"]);?></li>
                    <li><strong>[Diện tích khuôn viên]:</strong></li>
                    <li><?php echo showData($property["w"])."m x ".showData($property["d"])."m" ;?></li>
                    <li><strong>[Diện tích sàn]:</strong></li>
                    <li><?php echo showData(format_thousand($property["area_build"]))." m2" ;?></li>
                    <li><strong>[Diện tích sử dụng]:</strong></li>
                    <li><?php echo showData(format_thousand($property["area_use"]))." m2" ;?></li>
                    <li><strong>[Số tầng]:</strong></li>
                    <li><?php echo showData($property["floor"]);?></li>
                    <li><strong>[Phòng khách]:</strong></li>
                    <li><?php echo showData($property["floor"]);?></li>
                    <li><strong>[Phòng ngủ]:</strong></li>
                    <li><?php echo showData($property["floor"]);?></li>
                    <li><strong>[Phòng tắm]:</strong></li>
                    <li><?php echo showData($property["floor"]);?></li>
                    <li class="end1"><strong>[Phòng bếp]:</strong></li>
                    <li class="end1"><?php echo showData($property["floor"]);?></li>
                </ul>

            </div>
            <div class="line_info" style="border-left:1px solid #ff7319;">
                <ul>
                    <li><strong>[Pháp lý]:</strong></li>
                    <li><?php echo showData($property["legal_doc"]);?></li>
                    <li><strong>[Hướng]:</strong></li>
                    <li><?php echo showData(show_direction($property["direction"]));?></li>
                    <li><strong>[Đường trước nhà]:</strong></li>
                    <li><?php echo showData($property["way"])." m" ;?></li>
                    <li><strong>[Năm xây dựng]:</strong></li>
                    <li><?php echo showData($property["build_year"]);?></li>
                    <li><strong>[Năm sửa chữa]:</strong></li>
                    <li><?php echo showData($property["repair_year"]);?></li>
                    <li><strong>[Chỗ để Ôtô]</strong></li>
                    <li><?php if($property["gara_oto"]=="yes") echo "Có"; else echo "Không"; ?></li>
                    <li><strong>[Tổ chức định giá]:</strong></li>
                    <li><?php echo showData($property["org_price"]);?></li>
                    <li><strong>[Ngày định giá]:</strong></li>
                    <li><?php echo showData($property["date_price"]);?></li>
                    <li class="end1"><strong>[Ngày đăng tin]:</strong></li>
                    <li class="end1"><?php echo showData($property["create_date"]);?></li>


                </ul>

            </div>
        </div>
        <div class="info_left<?php echo $class_des; ?>" style="">
            <div style="font-weight: bold;font-size: 12px;padding:10px;">[MÔ TẢ VỀ SẢN PHẨM]</div>
            <div style="font-size: 12px;padding-left: 20px">
                <?php echo $property["description"];?>
            </div>
        </div>
        <div class="info_user_news" >
            <div style="color: red;font-weight: bold;font-size: 12px;padding:10px">[THÔNG TIN LIÊN HỆ]</div>
            <div class="infouser1" >
                <ul>
                    <li>[Người đăng tin]: <b><?php echo $arr_contact["name"];?></b></li>
                    <li>Email: <b><?php echo $arr_contact["email"];?></b></li>
                    <li>[Điện thoại]: <b><?php echo $arr_contact["phone"];?></b></li>
                    <li>[Di động]: <b><?php echo $arr_contact["mobile"];?></b></li>
                    <li>[Địa chỉ]: <b><?php echo $arr_contact["address"];?></b></li>
                </ul>
            </div>
        </div>
        <div class="tab_sanBDS_ct">
            <ul class="tab_sanBDS">
                <li class="current" id="tab1"><a href="javascript:void(0);" onclick="show_tab(1);"><b>[Cùng khoảng giá]</b></a></li>
                <li id="tab2"><a href="javascript:void(0);" onclick="show_tab(2);"><b>[Cùng thời gian đăng]</b></a></li>
            </ul>
        </div>
        <?php
        $_SESSION["tt"]=0;
        //Tab1
        $maxPrice = $property['price']+10;
        $minPrice = $property['price']-10;
        $rs_property = get_all_property("AND (price < $maxPrice AND price > $minPrice ) AND type='".$property['type']."' AND id != ".$property['id']);
        get_div_tab(1,$rs_property);
        //Tab2
        $rs_property2 = get_all_property('AND create_date LIKE "%'.get_my_date($property["create_date"],'Y-m-d').'%" AND type='."'".$property['type']."' AND id != ".$property['id']);
        get_div_tab(2,$rs_property2);

        function get_div_tab($tab,$rs) {
            global $db,$property;

            $style = "style='display:none'";
            if($tab==1)$style="";

            ?>
        <div id="div_tab<?php echo $tab; ?>" <?php echo $style; ?> >

            <div class="tab_sanBDS_info">

                    <?php

                    while($row=$db->fetch_array($rs["property"])) {
                        $_SESSION["tt"]++;
                        ?>

                <div class="div_content2">

                    <div class="infocontent3">
                        <a href="<?php echo get_link("property","detail",$row['title_link']); ?>" title="<?php echo htmlentities_utf8($row['title']);?>"><b><?php echo limitWord($row["title"],15); ?></b></a>
                        <p style="color:#777;"><img src="<?php echo SITE_IMAGES_URL; ?>/point.gif" />[Giá]: <?php echo get_price_string($row["price"]);?></p>
                        <p style="color:#777;"><img src="<?php echo SITE_IMAGES_URL; ?>/point.gif" />[Loại BĐS]: <a class="textgray" href="#"><?php echo get_cat_property($row["cat_id"]); ?></a></p>
                    </div>

                    <div class="showcontent" id="neocat-<?php echo $_SESSION["tt"]; ?>">
                        <img src="<?php echo SITE_IMAGES_URL; ?>/luu.gif" />&nbsp;<a href="#">[Lưu]</a><a href="#">&nbsp;l&nbsp;</a><img src="<?php echo SITE_IMAGES_URL; ?>/chitiet.gif" />&nbsp;<a href="<?php echo get_link("property","detail",$row['title_link']); ?>" title="<?php echo htmlentities_utf8($row['title']);?>">[Chi tiết]</a>
                    </div>
                </div>

                        <?php  } ?>

            </div>

                <?php

                if($rs["total"]>1) {

                    echo paging_ajax($rs["page"],$rs["total"],$tab,$property["type"],$property["price"],$property["id"]);

                }

                ?>

        </div>

            <?php } //end get div tab ?>
    </div>

</div>

<!--[if IE 7]><!-->

<!--<![endif]-->
<!--[if lte IE 6]>

<![endif]-->


<div id="sendFriend" class="folder-body00" style="display: none;height:350px" >
    <script type="text/javascript" language="javascript">
        function checkEmail(address) {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if(reg.test(address) == false) {
                return false;
            }
            return true;
        }
        function submitSendFriend()
        {
            if($('#name').val()==''){
                $('#name').attr('border-color', 'red', 'style');
                $('#name').focus();
                return false;
            }
            if($('#email_to').val()==''){
                $('#email_to').attr('border-color', 'red', 'style');
                $('#email_to').focus();
                return false;
            }
            if(checkEmail($('#email_to').val())==false){
                alert('Bạn nhập email không đúng, xin vui lòng nhập lại!');
                $('#email_to').focus();
                return false;
            }
            if($('#title').val()==''){
                $('#title').attr('border-color', 'red', 'style');
                $('#title').focus();
                return false;
            }
            if($('#content').val()==''){
                $('#content').attr('border-color', 'red', 'style');
                $('#content').focus();
                return false;
            }

            $.ajax({
                url: AJAX_PROCESS_URL+'sendFiend',
                type: 'post',
                data: "name="+$('#name').val()+'&email_from='+$('#email_from').val()+'&email_to='+$('#email_to').val()+'&title='+$('#title').val()+'&content='+$('#content').val()+'&url='+window.location.href,
                error: function(){
                    alert('Connection error!');
                },
                success: function(data){
                    if(data=='die'){
                        alert('Error');
                    }
                    $('#TB_closeWindowButton').click()
                }
            });

        }


    </script>

    <div class="line_dangtin" style="margin-left: 20px;font-weight: bold;margin-top: 20px;width: 97%">
        <div><?php echo $_SESSION['msgContact'];unset ($_SESSION['msgContact'])?></div>
        <form id="frmSendFriend" method="POST" onsubmit="">
            <ul>
                <li>
                    <div class="line_dt_l" style="width: 22%;">[Tên của bạn] <font color="#f87310">(*)</font></div>
                    <div class="line_dt_r"><input type="text" id="name" name="name" style="width: 80%;"></div>
                </li>
                <li>
                    <div class="line_dt_l" style="width: 24%;">[Email người nhận] <font color="#f87310">(*)</font></div>
                    <div class="line_dt_r">
                        <input type="text" id="email_to" name="email_to" style="width: 80%;"/>
                    </div>
                </li>
                <li>
                    <div class="line_dt_l" style="width: 22%;">[Tiêu đề] <font color="#f87310">(*)</font></div>
                    <div class="line_dt_r"><input type="text" style="width: 80%;" value="" id="title" name="title"></div>
                </li>
                <li>
                    <div class="line_dt_l" style="width: 22%;">[Nội dung] <font color="#f87310">(*)</font></div>
                    <div class="line_dt_r"><textarea id="content" name="content" rows="6" cols="20" style="width:80%;height: 100px;"></textarea></div>
                </li>
                <li >
                    <div class="line_dt_l" style="width: 22%;">&nbsp;</div>
                    <input type="hidden" name="post_contact" value="okie" />
                    <div class="line_dt_r"><img style="cursor: pointer" src="/images/btn_send.gif" onclick="submitSendFriend();" name="sendFriendSubmit"/></div>
                </li>


            </ul>
        </form>
    </div>
</div>
